package com.rural.bus.driver;

import java.util.Timer;
import java.util.TimerTask;

import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import com.rural.bus.driver.config.MyPreferenceManager;
import com.rural.bus.driver.config.PreferenceKey;
import com.rural.bus.driver.utils.CommonTools;

public class GuideActivity extends BaseActivity {

	private Timer timer;
	private TimerTask task;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		/* set it to be no title */
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		/* set it to be full screen */
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

		setContentView(R.layout.activity_guide, false);

		initView();
		setListeners();

		initData();
	}

	protected void setListeners() {

	}

	@Override
	protected void initView() {

	}

	@Override
	protected void initData() {
		timer = new Timer();
		task = new TimerTask() {
			@Override
			public void run() {
				if (MyApplication.driverInfo == null) {
					goLoginIn();
				} else {
					goMain();
				}
			}
		};
		timer.schedule(task, 1000 * 3); // 3秒后
	}

	private void goLoginIn() {
		if(timer != null){
			timer.cancel();
		}
		if(task != null){
			task.cancel();
		}
		startActivity(new Intent(this, LoginActivity.class));
		this.finish();
		
	}

	private void goMain() {
		if(timer != null){
			timer.cancel();
		}
		if(task != null){
			task.cancel();
		}
		startActivity(new Intent(this, MainActivity.class));
		this.finish();
	}

}
